﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="mtamaruosad_osa", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MtamaruosadOsa))]
    public class MtamaruosadOsaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMtamaruosadOsa clazz;
        
        public MtamaruosadOsaSerializer(IMtamaruosadOsa clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("rea_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.ReaId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("mosa_tyyp");
            if (clazz.MosaTyyp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MosaTyyp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : MosaTyyp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kuupaev");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Kuupaev))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="rea_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamaruosad_osa>rea_id");
                }
                clazz.ReaId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("rea_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamaruosad_osa>rea_id", Reader.LocalName);
            }
            if (Reader.LocalName=="mosa_tyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamaruosad_osa>mosa_tyyp");
                }
                clazz.MosaTyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("mosa_tyyp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamaruosad_osa>mosa_tyyp", Reader.LocalName);
            }
            if (Reader.LocalName=="kuupaev") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtamaruosad_osa>kuupaev");
                }
                clazz.Kuupaev = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kuupaev")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtamaruosad_osa>kuupaev", Reader.LocalName);
            }
        }
    }
}
